package org.lgiavedoni.android.franq.event.listener.sms;

import org.lgiavedoni.android.franq.core.bean.SMS;
import org.lgiavedoni.android.franq.core.envent.Event;
import org.lgiavedoni.android.franq.core.envent.listener.EventListener;
import org.lgiavedoni.android.franq.core.question.imp.TextQuestion;
import org.lgiavedoni.android.franq.core.question.imp.YesOrNoQuestion;
import org.lgiavedoni.android.franq.core.speak.CommonPhraseHelper;
import org.lgiavedoni.android.franq.event.SMSFromEvent;
import org.lgiavedoni.android.franq.event.listener.sms.notification.SMSFromUserNotification;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;
import org.lgiavedoni.android.franq.service.phone.sms.SMSService;
import org.lgiavedoni.android.franq.service.question.QuestionService;

public class SMSFromEventListener extends EventListener {

	@Override
	public void exec(Event event) {
		SMS sms = ((SMSFromEvent) event).getSms();

		CommunicationService.inst.sendMessage(new SMSFromUserNotification(sms));
		YesOrNoQuestion replay = (YesOrNoQuestion) QuestionService.inst.askNowAndWait(new YesOrNoQuestion("Do you want to replay?"));
		if (replay.getResultValue() != null && replay.getResultValue().booleanValue()) {
			TextQuestion messageQuestion = (TextQuestion) QuestionService.inst.askNowAndWait(new TextQuestion("Message?"));
			String message = messageQuestion.getResultValue();
			SMSService.inst.sendSMS(sms.getFrom(), message);
			CommunicationService.inst.sendMessage(CommonPhraseHelper.DONE);
		}

	}

	@Override
	public Class<SMSFromEvent> getClassEvent() {
		return SMSFromEvent.class;
	}

}
